var viewport;
var tab;
var Tree = Ext.tree;
   var selNode = null;
var loadMask ;
//设置树的点击事件 
function treeClick(node,e) { 
 //alert(node.id);
	 if(!node.isLeaf()){
		e.stopEvent();
		var n = tab.getComponent(node.id); 
		if (!n) {
			if(node.id == 1){
				var n = tab.add({
					'id' : node.id,
					'title' : node.text,
					 autoShow:true,
					 autoDestroy : false,
					 closable:true,
					 autoLoad:{url:'sortTree.jsp', scripts:true}
					// html:'<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="sortTree.jsp"></iframe>'
	
					});
			}else{
			    var url = '';
			    if(node.id == 2){
			      url = '';
			    }
			    if(node.id == 3){
			       url = 'admin/preImport.jsp';
			    } 
			    if(node.id == 4){
			       url = 'pre/preIndex.do';
			    } 
			    if(node.id == 5){
			       url = '../admin/job.do';
			    } 
			    if(node.id == 6){
			       url = '../admin/gather.do';
			    } 
			     if(node.id == 7){
			       url = '../user.do?userDis=listUser';
			    }
				var n = tab.add({
					'id' : node.id,
					'title' : node.text,
					 autoShow:true,
					 autoDestroy : false,
					 closable:true,
					 html:'<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="'+url+'"></iframe>'
					}); 
			
			}
		}
		tab.setActiveTab(n);
	 } 
}
//设置树的点击事件 
function treeClick1(node,e) { 
 //alert(node.id);
	 if(!node.isLeaf()){
		e.stopEvent();
		var n = tab.getComponent(node.id);
		if (!n) {
			var n = tab.add({
				'id' : node.id,
				'title' : node.text,
				closable:true,
				 html:'<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="search/index1.jsp"></iframe>'

				});
		}
		tab.setActiveTab(n);
	 }
}

//生成标签页
tab = new Ext.TabPanel({
			region:'center',
			resizeTabs:true, // turn on tab resizing
        minTabWidth: 115,
        tabWidth:135,
        enableTabScroll:true,
        width:600,
        height:250,
        defaults: {autoScroll:true}
		});
		
		 
        
Ext.onReady(function(){
   //layout
    viewport = new Ext.Viewport({
		layout:'border',
		items:[
			new Ext.BoxComponent({
				region:'north',
				el: 'north',
				height:80
			}),new Ext.BoxComponent({
				region:'south',
				el: 'south',
				height:25
			}),{
			region:'west',
			id:'west-panel',
			split:true,
			width: 200,
			minSize: 0,
			maxSize: 400,
			margins:'0 0 0 0',
			layout:'accordion',
			title:'欢迎使用',
			collapsible :true,
			layoutConfig:{
				animate:true
				},
		    items: [
			    {
					title:'<b>数据维护</b>',
					border:false,
					html:'<div id="tree-div1" style="overflow:auto;width:100%;height:100%"></div>'
					//iconCls:'nav'
			    },{
					title:'<b>分类导航</b>',
					border:false,
					//iconCls:'settings',
					html:'<div id="tree-div2" style="overflow:auto;width:100%;height:100%"></div>'
			    },{
					title:'<b>数据分析</b>',
					border:false,
					//iconCls:'settings',
					html:'<div id="tree-div3" style="overflow:auto;width:100%;height:100%"></div>'
			    },{
					title:'<b>权限管理</b>',
					border:false,
					//iconCls:'settings',
					html:'<div id="tree-div4" style="overflow:auto;width:100%;height:100%"></div>'
			    },{
					title:'<b>知识管理</b>',
					border:false,
					//iconCls:'settings',
					html:'<div id="tree-div5" style="overflow:auto;width:100%;height:100%"></div>'
			    },{
					title:'<b>个人设置</b>',
					border:false,
					//iconCls:'settings',
					html:'<div id="tree-div6" style="overflow:auto;width:100%;height:100%"></div>'
			    }]
			},
	        tab//初始标签页
		 ]
	});

  loadMask =  new Ext.LoadMask(tab.body,{msg:"页面加载中……"}); 
	//设置树形面板
	var Tree = Ext.tree;
	// set the root node
	var root = new Tree.AsyncTreeNode({
		text: 'Ext JS',
		draggable:false,
		id:'1'
	});

	var tree = new Tree.TreePanel({
		el:'tree-div1',
		autoScroll:true,
		root:root,
		animate:true,
		enableDD:false,
		border:false,
		rootVisible:false,
		containerScroll: true
		//,
		//loader: new Tree.TreeLoader({
			//dataUrl:'pre/indexTree.do?action=index',
            //baseParams:{menuId:1}
		//})
	});
	//页面打开时加载
    //tree.on("beforeload", function(treeLoader, node) {
	// 	tree.loader.baseParams.menuId = treeLoader.id;
    //	}, this);
   // tree.setRootNode(root);
	// render the tree
	tree.render();
	root.expand();
	tree.on('click',treeClick);
	root.appendChild(root_1);
	//root.appendChild(root_2);
	root.appendChild(root_3);
	root.appendChild(root_4);
	root.appendChild(root_5);
	root.appendChild(root_6);


////////////////////////////////////////////////////////////////////
// set the root node
	var root2 = new Tree.AsyncTreeNode({
		text: 'Ext JS',
		draggable:false,
		id:'2'
	});
   var tree2 = new Tree.TreePanel({
		el:'tree-div2',
		autoScroll:true,
		root:root2,
		animate:true,
		enableDD:false,
		border:false,
		rootVisible:false,
		containerScroll: true,
		loader: new Tree.TreeLoader({
			dataUrl:'pre/indexTree.do?action=index',
            baseParams:{menuId:2}
		})
	});
	//页面打开时加载
    tree2.on("beforeload", function(treeLoader, node) {
	 	tree2.loader.baseParams.menuId = treeLoader.id;
    	}, this);
    tree2.setRootNode(root2);
	// render the tree
	tree2.render();
	root2.expand();
	tree2.on('click',treeClick1);
/////////////////////////////////////////////////////////
var root3 = new Tree.AsyncTreeNode({
		text: 'Ext JS',
		draggable:false,
		id:'3'
	});
   var tree3 = new Tree.TreePanel({
		el:'tree-div3',
		autoScroll:true,
		root:root3,
		animate:true,
		enableDD:false,
		border:false,
		rootVisible:false,
		containerScroll: true,
		loader: new Tree.TreeLoader({
			dataUrl:'pre/indexTree.do?action=index',
            baseParams:{menuId:3}
		})
	});
	//页面打开时加载
    tree3.on("beforeload", function(treeLoader, node) {
	 	tree3.loader.baseParams.menuId = treeLoader.id;
    	}, this);
    tree3.setRootNode(root3);
	// render the tree
	tree3.render();
	root3.expand();
	tree3.on('click',treeClick);
//////////////////////////////////////////////
var root4 = new Tree.TreeNode({
		text: 'Ext JS',
		draggable:false,
		id:'4'
	});
root4.appendChild(root_7);//用户管理 
	
	
   var tree4 = new Tree.TreePanel({
		el:'tree-div4',
		autoScroll:true,
		root:root4,
		animate:true,
		enableDD:false,
		border:false,
		rootVisible:false,
		containerScroll: true
		//,
	//	loader: new Tree.TreeLoader({
		//	dataUrl:'pre/indexTree.do?action=index',
       //     baseParams:{menuId:4}})
	});
	   var node001 = new Tree.TreeNode({
        text: '分类',
        id:'7'
    });
    root4.appendChild(node001);
	//页面打开时加载
   // tree4.on("beforeload", function(treeLoader, node) {
	// 	tree4.loader.baseParams.menuId = treeLoader.id;
    //	}, this);
   // tree4.setRootNode(root4);
	// render the tree
	tree4.render();
	root4.expand();
	tree4.on('click',treeClick);
	/////////////////////////////////////
	var root5 = new Tree.AsyncTreeNode({
		text: 'Ext JS',
		draggable:false,
		id:'5'
	});
   var tree5 = new Tree.TreePanel({
		el:'tree-div5',
		autoScroll:true,
		root:root5,
		animate:true,
		enableDD:false,
		border:false,
		rootVisible:false,
		containerScroll: true,
		loader: new Tree.TreeLoader({
			dataUrl:'pre/indexTree.do?action=index',
            baseParams:{menuId:5}
		})
	});
	//页面打开时加载
    tree5.on("beforeload", function(treeLoader, node) {
	 	tree5.loader.baseParams.menuId = treeLoader.id;
    	}, this);
    tree5.setRootNode(root5);
	// render the tree
	tree5.render();
	root5.expand();
	tree5.on('click',treeClick);
	//////////////////////////////
	var root6 = new Tree.AsyncTreeNode({
		text: 'Ext JS',
		draggable:false,
		id:'6'
	});
   var tree6 = new Tree.TreePanel({
		el:'tree-div6',
		autoScroll:true,
		root:root6,
		animate:true,
		enableDD:false,
		border:false,
		rootVisible:false,
		containerScroll: true,
		loader: new Tree.TreeLoader({
			dataUrl:'pre/indexTree.do?action=index',
            baseParams:{menuId:6}
		})
	});
	//页面打开时加载
    tree6.on("beforeload", function(treeLoader, node) {
	 	tree6.loader.baseParams.menuId = treeLoader.id;
    	}, this);
    tree6.setRootNode(root6);
	// render the tree
	tree6.render();
	root6.expand();
	tree6.on('click',treeClick);
	//end loding
	setTimeout(
				function() {
					Ext.get('loading').remove();
					Ext.get('loading-mask').fadeOut({remove:true});
				}, 250
			  );
});
 var root_1=new Ext.tree.TreeNode({
		id:'1',
		icon:'../app/images/dian.gif',
		text:'<b>  标准分类</b>'
	});
var root_2=new Ext.tree.TreeNode({
		id:'2',
		icon:'../app/images/dian.gif',
		text:'<b>  分类导入</b>'
	});
var root_3=new Ext.tree.TreeNode({
		id:'3',
		icon:'../app/images/dian.gif',
		text:'<b>  方剂导入</b>'
	});
var root_4=new Ext.tree.TreeNode({
		id:'4',
		icon:'../app/images/dian.gif',
		text:'<b>  索引维护</b>'
	});
var root_5=new Ext.tree.TreeNode({
		id:'5',
		icon:'../app/images/dian.gif',
		text:'<b>  任务管理</b>'
	});
var root_6=new Ext.tree.TreeNode({
		id:'6',
		icon:'../app/images/dian.gif',
		text:'<b>  数据采集</b>'
	});

	var root_7=new Ext.tree.TreeNode({
		id:'7',
		icon:'../app/images/dian.gif',
		text:'<b>  用户管理</b>'
	});
	